public class JShell {
	
	JSInputOutput io;
	JSParser parser;
	JSCommander commander;
	JSDirectory workDir;
	
	private static final String EXIT_MESSAGE = "Goodbye!";
	
	public JShell() {
		io = new InputOutput();
		parser = new Parser();
		commander = new Commander();
		workDir = new Directory();
	}
	
	public JSDirectory getWorkDir() {
		return workDir;
	}
	
	public void setWorkDir(JSDirectory newDir) {
		workDir = newDir;
	}
	
	public void runShell() {
		
		// Initialize variables
		String input;
		String output;
		String[] parsedArgs;
		
		// Exit flag
		Boolean exit = false;
		
		// Continue to run until exit condition
		while (!exit) {
		
			//Prompt for user input
			input = io.userPrompt(workDir);
			
			// Continue to operate on input only if the input has content,
			// i.e., if the user hasn't merely pressed Enter
			if (input.length() != 0) {
			
				// Check for exit condition
				if (input.compareToIgnoreCase("exit") == 0) {
					exit = true;
					io.print(EXIT_MESSAGE);
					
				// Check for the empty input, i.e. if user merely pressed Enter
				// Else compute appropriate output and continue to prompt
				} else {
				 	parsedArgs = parser.parseString(input);
					output = commander.runCommand(parsedArgs, this); 
					io.print(output);
				}
			}
		}
	}

	public static void main(String[] args) {
		JShell shell = new JShell();
		shell.runShell();
	}

}
